package csx.study.demo.controller;

import csx.study.demo.dto.Result;
import csx.study.demo.dto.VoucherDTO;
import csx.study.demo.entity.Voucher;
import csx.study.demo.service.IVoucherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author csx
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/voucher")
public class VoucherController {

    @Resource
    private IVoucherService voucherService;

    /**
     * 新增普通券
     * @param voucherDTO 优惠券信息
     * @return 优惠券id
     */
    @PostMapping
    public Result addVoucher(@RequestBody VoucherDTO voucherDTO) {
        return voucherService.addVoucher(voucherDTO);
    }

    /**
     * 新增秒杀券
     * @param voucherDTO 优惠券信息，包含秒杀信息
     * @return 优惠券id
     */
    //管理用的，用apifox测试
    @PostMapping("seckill")
    public Result addSeckillVoucher(@RequestBody VoucherDTO voucherDTO) {
        return voucherService.addSeckillVoucher(voucherDTO);
    }

    /**
     * 查询店铺的优惠券列表
     * @param shopId 店铺id
     * @return 优惠券列表
     */
    @GetMapping("/list/{shopId}")
    public Result queryVoucherOfShop(@PathVariable("shopId") Long shopId) {
        return voucherService.queryVoucherOfShop(shopId);
    }
}
